home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 17585 < prev    next >
Mailbox/MIME Entity  |  1996-08-05  |  2.2 KB

open in: MacOS 8.1     |     Win98     |     DOS

browse contents    |     view JSON data     |     view as text


This file was processed as: Mailbox/MIME Entity (archive/mbox).

ConfidenceProgramDetectionMatch TypeSupport
100% dexvert Newsgroup Content (archive/news) magic Supported
100% dexvert Mailbox/MIME Entity (archive/mbox) magic Supported
1% dexvert Text File (text/txt) fallback Supported
100% file news text default
99% file C++ source text default
98% file C++ source, ASCII text default
100% checkBytes Printable ASCII default
100% dexmagic PrintFox/Pagefox WEAK default
100% perlTextCheck Likely Text (Perl) default
100% siegfried fmt/950 MIME Email (1.0) default
100% detectItEasy Format: plain text[LF] default (weak)
100% xdgMime message/news default



hex view
+--------+-------------------------+-------------------------+--------+--------+
|00000000| 50 61 74 68 3a 20 6e 65 | 77 73 2e 65 75 6e 65 74 |Path: ne|ws.eunet|
|00000010| 2e 63 68 21 75 73 65 6e | 65 74 0a 46 72 6f 6d 3a |.ch!usen|et.From:|
|00000020| 20 4f 6c 69 76 65 72 20 | 50 6c 6f 68 6d 61 6e 6e | Oliver |Plohmann|
|00000030| 20 3c 6f 70 6c 40 65 73 | 65 63 2e 63 68 3e 0a 4e | <opl@es|ec.ch>.N|
|00000040| 65 77 73 67 72 6f 75 70 | 73 3a 20 63 6f 6d 70 2e |ewsgroup|s: comp.|
|00000050| 6c 61 6e 67 2e 63 2b 2b | 0a 53 75 62 6a 65 63 74 |lang.c++|.Subject|
|00000060| 3a 20 52 65 3a 20 48 6f | 77 20 64 6f 20 49 20 70 |: Re: Ho|w do I p|
|00000070| 75 74 20 44 49 46 46 45 | 52 45 4e 54 20 63 6c 61 |ut DIFFE|RENT cla|
|00000080| 73 73 65 73 20 69 6e 20 | 74 68 65 20 73 61 6d 65 |sses in |the same|
|00000090| 20 6c 69 6e 6b 65 64 20 | 6c 69 73 74 3f 0a 44 61 | linked |list?.Da|
|000000a0| 74 65 3a 20 54 75 65 2c | 20 31 36 20 41 70 72 20 |te: Tue,| 16 Apr |
|000000b0| 31 39 39 36 20 31 30 3a | 31 31 3a 34 32 20 2b 30 |1996 10:|11:42 +0|
|000000c0| 32 30 30 0a 4f 72 67 61 | 6e 69 7a 61 74 69 6f 6e |200.Orga|nization|
|000000d0| 3a 20 45 53 45 43 20 53 | 41 0a 4d 65 73 73 61 67 |: ESEC S|A.Messag|
|000000e0| 65 2d 49 44 3a 20 3c 33 | 31 37 33 35 36 33 45 2e |e-ID: <3|173563E.|
|000000f0| 31 36 44 46 40 65 73 65 | 63 2e 63 68 3e 0a 52 65 |16DF@ese|c.ch>.Re|
|00000100| 66 65 72 65 6e 63 65 73 | 3a 20 3c 34 6b 61 39 33 |ferences|: <4ka93|
|00000110| 38 24 62 6a 36 40 77 69 | 6e 74 65 72 6d 75 74 65 |8$bj6@wi|ntermute|
|00000120| 2e 65 63 73 2e 66 75 6c | 6c 65 72 74 6f 6e 2e 65 |.ecs.ful|lerton.e|
|00000130| 64 75 3e 20 3c 6d 61 72 | 6e 6f 6c 64 44 70 4a 39 |du> <mar|noldDpJ9|
|00000140| 48 4b 2e 34 31 44 40 6e | 65 74 63 6f 6d 2e 63 6f |HK.41D@n|etcom.co|
|00000150| 6d 3e 0a 4e 4e 54 50 2d | 50 6f 73 74 69 6e 67 2d |m>.NNTP-|Posting-|
|00000160| 48 6f 73 74 3a 20 65 76 | 65 72 65 73 74 2e 65 73 |Host: ev|erest.es|
|00000170| 65 63 2e 63 68 0a 4d 69 | 6d 65 2d 56 65 72 73 69 |ec.ch.Mi|me-Versi|
|00000180| 6f 6e 3a 20 31 2e 30 0a | 43 6f 6e 74 65 6e 74 2d |on: 1.0.|Content-|
|00000190| 54 79 70 65 3a 20 74 65 | 78 74 2f 70 6c 61 69 6e |Type: te|xt/plain|
|000001a0| 3b 20 63 68 61 72 73 65 | 74 3d 75 73 2d 61 73 63 |; charse|t=us-asc|
|000001b0| 69 69 0a 43 6f 6e 74 65 | 6e 74 2d 54 72 61 6e 73 |ii.Conte|nt-Trans|
|000001c0| 66 65 72 2d 45 6e 63 6f | 64 69 6e 67 3a 20 37 62 |fer-Enco|ding: 7b|
|000001d0| 69 74 0a 58 2d 4d 61 69 | 6c 65 72 3a 20 4d 6f 7a |it.X-Mai|ler: Moz|
|000001e0| 69 6c 6c 61 20 32 2e 30 | 20 28 58 31 31 3b 20 49 |illa 2.0| (X11; I|
|000001f0| 3b 20 48 50 2d 55 58 20 | 41 2e 30 39 2e 30 35 20 |; HP-UX |A.09.05 |
|00000200| 39 30 30 30 2f 37 33 35 | 29 0a 54 6f 3a 20 4d 61 |9000/735|).To: Ma|
|00000210| 74 74 20 41 72 6e 6f 6c | 64 20 3c 6d 61 72 6e 6f |tt Arnol|d <marno|
|00000220| 6c 64 40 6e 65 74 63 6f | 6d 2e 63 6f 6d 3e 0a 0a |ld@netco|m.com>..|
|00000230| 3e 20 3e 49 27 6d 20 74 | 72 79 69 6e 67 20 74 6f |> >I'm t|rying to|
|00000240| 20 77 72 69 74 65 20 61 | 20 70 72 6f 67 72 61 6d | write a| program|
|00000250| 20 77 68 65 72 65 20 49 | 20 6e 65 65 64 20 74 6f | where I| need to|
|00000260| 20 6d 61 69 6e 74 61 69 | 6e 20 61 20 6c 69 6e 6b | maintai|n a link|
|00000270| 65 64 20 6c 69 73 74 20 | 6f 66 0a 3e 20 3e 76 61 |ed list |of.> >va|
|00000280| 72 69 6f 75 73 20 69 74 | 65 6d 73 2e 20 45 61 63 |rious it|ems. Eac|
|00000290| 68 20 69 74 65 6d 20 69 | 73 20 61 20 63 6c 61 73 |h item i|s a clas|
|000002a0| 73 2c 20 62 75 74 20 65 | 61 63 68 20 69 74 65 6d |s, but e|ach item|
|000002b0| 20 69 73 20 64 69 66 66 | 65 72 65 6e 74 20 66 72 | is diff|erent fr|
|000002c0| 6f 6d 20 61 6e 6f 74 68 | 65 72 0a 3e 20 3e 69 74 |om anoth|er.> >it|
|000002d0| 65 6d 2e 20 4c 65 74 20 | 6d 65 20 67 69 76 65 20 |em. Let |me give |
|000002e0| 61 6e 20 65 78 61 6d 70 | 6c 65 20 74 6f 20 63 6c |an examp|le to cl|
|000002f0| 61 72 69 66 79 3a 0a 0a | 48 65 6c 6c 6f 2c 0a 0a |arify:..|Hello,..|
|00000300| 49 20 68 61 76 65 6e 27 | 74 20 66 6f 6c 6c 6f 77 |I haven'|t follow|
|00000310| 65 64 20 74 68 65 20 74 | 68 72 65 61 64 20 77 68 |ed the t|hread wh|
|00000320| 65 74 68 65 72 20 75 73 | 69 6e 67 20 76 69 72 74 |ether us|ing virt|
|00000330| 75 61 6c 20 66 75 6e 63 | 74 69 6f 6e 73 20 77 69 |ual func|tions wi|
|00000340| 6c 6c 20 64 6f 20 77 61 | 6e 74 20 79 6f 75 20 77 |ll do wa|nt you w|
|00000350| 65 72 65 20 6c 6f 6f 6b | 69 6e 67 0a 66 6f 72 2e |ere look|ing.for.|
|00000360| 20 42 75 74 20 69 6e 73 | 65 72 74 69 6e 67 20 69 | But ins|erting i|
|00000370| 6e 73 74 61 6e 63 65 73 | 20 6f 66 20 64 69 66 66 |nstances| of diff|
|00000380| 65 72 65 6e 74 20 63 6c | 61 73 73 65 73 20 69 6e |erent cl|asses in|
|00000390| 74 6f 20 61 20 70 61 72 | 61 6d 65 74 65 72 69 7a |to a par|ameteriz|
|000003a0| 65 64 20 6c 69 6e 6b 65 | 64 20 6c 69 73 74 20 6e |ed linke|d list n|
|000003b0| 6f 64 65 20 69 73 20 6e | 6f 74 0a 70 6f 73 73 69 |ode is n|ot.possi|
|000003c0| 62 6c 65 2e 0a 0a 57 68 | 61 74 20 79 6f 75 20 63 |ble...Wh|at you c|
|000003d0| 61 6e 20 64 6f 20 69 73 | 20 63 61 73 74 20 74 6f |an do is| cast to|
|000003e0| 20 76 6f 69 64 2a 2e 20 | 57 68 65 6e 20 79 6f 75 | void*. |When you|
|000003f0| 20 67 65 74 20 74 68 65 | 20 6f 62 6a 65 63 74 20 | get the| object |
|00000400| 6f 75 74 20 6f 66 20 74 | 68 65 20 6c 69 6e 6b 65 |out of t|he linke|
|00000410| 64 20 6c 69 73 74 20 79 | 6f 75 20 6e 65 65 64 20 |d list y|ou need |
|00000420| 74 6f 0a 63 61 73 74 20 | 62 61 63 6b 2e 20 54 68 |to.cast |back. Th|
|00000430| 69 73 20 69 73 20 64 61 | 6e 67 65 72 6f 75 73 20 |is is da|ngerous |
|00000440| 61 6e 64 20 6e 6f 20 67 | 6f 6f 64 20 70 72 6f 67 |and no g|ood prog|
|00000450| 72 61 6d 6d 69 6e 67 20 | 70 72 61 63 74 69 63 65 |ramming |practice|
|00000460| 2e 20 42 75 74 20 49 20 | 63 61 6e 27 74 20 73 65 |. But I |can't se|
|00000470| 65 20 61 6e 6f 74 68 65 | 72 20 73 6f 6c 75 74 69 |e anothe|r soluti|
|00000480| 6f 6e 0a 66 6f 72 20 74 | 68 69 73 20 65 78 63 65 |on.for t|his exce|
|00000490| 70 74 20 6f 66 20 75 73 | 69 6e 67 20 61 20 4d 6f |pt of us|ing a Mo|
|000004a0| 64 75 6c 61 20 73 74 79 | 6c 65 20 76 61 72 69 61 |dula sty|le varia|
|000004b0| 6e 74 20 72 65 63 6f 72 | 64 20 61 70 70 72 6f 61 |nt recor|d approa|
|000004c0| 63 68 20 77 68 69 63 68 | 20 69 73 20 74 65 64 69 |ch which| is tedi|
|000004d0| 6f 75 73 20 61 6e 64 20 | 61 20 77 61 73 74 65 20 |ous and |a waste |
|000004e0| 6f 66 0a 73 70 61 63 65 | 2e 0a 0a 59 6f 75 20 63 |of.space|...You c|
|000004f0| 61 6e 20 6d 61 6b 65 20 | 74 68 65 20 63 61 73 74 |an make |the cast|
|00000500| 20 6d 65 63 68 61 6e 69 | 73 6d 20 73 6d 61 72 74 | mechani|sm smart|
|00000510| 65 72 20 62 79 20 64 65 | 66 69 6e 69 6e 67 20 61 |er by de|fining a|
|00000520| 20 63 6c 61 73 73 20 53 | 6d 61 72 74 50 6f 69 6e | class S|martPoin|
|00000530| 74 65 72 20 77 68 69 63 | 68 20 79 6f 75 20 75 73 |ter whic|h you us|
|00000540| 65 20 61 73 20 74 68 65 | 0a 74 65 6d 70 6c 61 74 |e as the|.templat|
|00000550| 65 20 70 61 72 61 6d 65 | 74 65 72 20 69 6e 20 79 |e parame|ter in y|
|00000560| 6f 75 72 20 6c 69 6e 6b | 65 64 20 6c 69 73 74 2e |our link|ed list.|
|00000570| 0a 0a 63 6c 61 73 73 20 | 53 6d 61 72 74 50 6f 69 |..class |SmartPoi|
|00000580| 6e 74 65 72 0a 7b 0a 09 | 76 6f 69 64 2a 20 70 5f |nter.{..|void* p_|
|00000590| 3b 09 09 2f 2f 20 79 6f | 75 72 20 63 61 73 74 65 |;..// yo|ur caste|
|000005a0| 64 20 6f 62 6a 65 63 74 | 0a 09 63 68 61 72 2a 20 |d object|..char* |
|000005b0| 63 6c 61 73 73 4e 61 6d | 65 5f 3b 09 09 2f 2f 20 |classNam|e_;..// |
|000005c0| 6e 61 6d 65 20 6f 66 20 | 63 6c 61 73 73 20 74 6f |name of |class to|
|000005d0| 20 63 61 73 74 20 62 61 | 63 6b 20 74 6f 0a 0a 09 | cast ba|ck to...|
|000005e0| 53 6d 61 72 74 50 6f 69 | 6e 74 65 72 28 63 6f 6e |SmartPoi|nter(con|
|000005f0| 73 74 20 76 6f 69 64 2a | 20 70 6f 69 6e 74 65 72 |st void*| pointer|
|00000600| 2c 20 63 68 61 72 2a 20 | 6e 61 6d 65 29 20 7b 0a |, char* |name) {.|
|00000610| 09 09 70 5f 3d 70 6f 69 | 6e 74 65 72 3b 0a 09 09 |..p_=poi|nter;...|
|00000620| 63 6c 61 73 73 4e 61 6d | 65 5f 3d 6e 61 6d 65 3b |classNam|e_=name;|
|00000630| 0a 09 7d 3b 0a 0a 09 2f | 2f 20 63 6f 64 65 20 6f |..};.../|/ code o|
|00000640| 6d 69 74 74 65 64 20 2e | 2e 2e 0a 0a 7d 3b 0a 0a |mitted .|....};..|
|00000650| 63 6c 61 73 73 20 43 61 | 73 74 61 62 6c 65 43 6c |class Ca|stableCl|
|00000660| 61 73 73 20 7b 0a 0a 70 | 75 62 6c 69 63 3a 0a 0a |ass {..p|ublic:..|
|00000670| 09 76 6f 69 64 20 64 6f | 53 6f 6d 65 74 68 69 6e |.void do|Somethin|
|00000680| 67 28 29 3d 30 3b 0a 7d | 0a 0a 57 69 74 68 20 74 |g()=0;.}|..With t|
|00000690| 68 65 20 69 6e 66 6f 72 | 6d 61 74 69 6f 6e 20 69 |he infor|mation i|
|000006a0| 6e 20 63 6c 61 73 73 4e | 61 6d 65 5f 20 79 6f 75 |n classN|ame_ you|
|000006b0| 20 63 61 6e 20 72 75 6e | 20 74 68 72 6f 75 67 68 | can run| through|
|000006c0| 20 61 20 63 61 73 65 20 | 73 77 69 74 63 68 20 74 | a case |switch t|
|000006d0| 6f 20 63 61 73 74 20 62 | 61 63 6b 2e 20 54 68 65 |o cast b|ack. The|
|000006e0| 6e 20 79 6f 75 0a 63 61 | 6c 6c 20 61 20 76 69 72 |n you.ca|ll a vir|
|000006f0| 74 75 61 6c 20 66 75 6e | 63 74 69 6f 6e 20 64 6f |tual fun|ction do|
|00000700| 53 6f 6d 65 74 68 69 6e | 67 28 29 20 74 68 61 74 |Somethin|g() that|
|00000710| 20 69 73 20 69 6d 70 6c | 65 6d 65 6e 74 65 64 20 | is impl|emented |
|00000720| 66 6f 72 20 65 76 65 72 | 79 20 63 6c 61 73 73 20 |for ever|y class |
|00000730| 6f 66 20 77 68 69 63 68 | 20 69 6e 73 74 61 6e 63 |of which| instanc|
|00000740| 65 73 0a 61 72 65 20 61 | 64 64 65 64 20 74 6f 20 |es.are a|dded to |
|00000750| 74 68 65 20 6c 69 6e 6b | 65 64 20 6c 69 73 74 2e |the link|ed list.|
|00000760| 20 54 6f 20 75 73 65 20 | 74 68 65 20 63 6f 6d 70 | To use |the comp|
|00000770| 69 6c 65 72 20 74 6f 20 | 63 68 65 63 6b 20 66 6f |iler to |check fo|
|00000780| 72 20 74 68 69 73 20 61 | 6c 6c 20 6f 62 6a 65 63 |r this a|ll objec|
|00000790| 74 73 20 73 74 6f 72 65 | 64 20 69 6e 20 74 68 65 |ts store|d in the|
|000007a0| 0a 6c 69 73 74 20 6d 75 | 73 74 20 62 65 20 69 6e |.list mu|st be in|
|000007b0| 73 74 61 6e 63 65 73 20 | 6f 66 20 61 20 73 75 62 |stances |of a sub|
|000007c0| 63 6c 61 73 73 20 6f 66 | 20 43 61 73 74 61 62 6c |class of| Castabl|
|000007d0| 65 43 6c 61 73 73 2e 20 | 49 6e 20 45 69 66 66 65 |eClass. |In Eiffe|
|000007e0| 6c 20 69 74 20 69 73 20 | 70 6f 73 73 69 62 6c 65 |l it is |possible|
|000007f0| 20 74 65 6c 6c 20 74 68 | 65 0a 63 6f 6d 70 69 6c | tell th|e.compil|
|00000800| 65 72 20 74 68 61 74 20 | 74 68 65 20 70 61 72 61 |er that |the para|
|00000810| 6d 65 74 65 72 20 6f 66 | 20 61 20 70 61 72 61 6d |meter of| a param|
|00000820| 65 74 65 72 69 7a 65 64 | 20 63 6c 61 73 73 20 6d |eterized| class m|
|00000830| 75 73 74 20 62 65 20 61 | 20 63 65 72 74 61 69 6e |ust be a| certain|
|00000840| 20 63 6c 61 73 73 20 69 | 6e 63 6c 75 64 69 6e 67 | class i|ncluding|
|00000850| 20 69 74 73 0a 73 75 62 | 63 6c 61 73 73 65 73 2e | its.sub|classes.|
|00000860| 20 43 61 6e 27 74 20 73 | 65 65 20 68 6f 77 20 74 | Can't s|ee how t|
|00000870| 6f 20 64 6f 20 74 68 69 | 73 20 69 6e 20 43 2b 2b |o do thi|s in C++|
|00000880| 2c 20 74 68 6f 75 67 68 | 2e 0a 0a 52 65 67 61 72 |, though|...Regar|
|00000890| 64 73 2c 20 4f 6c 6c 69 | 20 50 6c 6f 68 6d 61 6e |ds, Olli| Plohman|
|000008a0| 6e 0a | |n. | |
+--------+-------------------------+-------------------------+--------+--------+